
package com.demo.user.exception;


import org.apache.commons.lang3.StringUtils;

/**
 * @author xiexiaohu
 */
public class BaseException extends RuntimeException {
    private static final long serialVersionUID = 1L;
    protected final DisplayableError errorCode;
    private Object[] args;

    /**
     * BaseException Constructor
     */
    public BaseException() {
        super();
        errorCode = EErrorCode.COMM_INTERNAL_ERROR;
    }


    /**
     * BaseException Constructor
     *
     * @param error
     */
    public BaseException(DisplayableError error) {
        this.errorCode = error;
    }


    /**
     * BaseException Constructor
     *
     * @param error
     * @param message
     */
    public BaseException(DisplayableError error, String message) {
        super(message);
        this.errorCode = error;

    }


    /**
     * BaseException Constructor
     *
     * @param error
     * @param message
     * @param cause
     */
    public BaseException(DisplayableError error, String message, Throwable cause) {
        super(message, cause);
        this.errorCode = error;
    }


    /**
     * BaseException Constructor
     *
     * @param error
     * @param message
     * @param args
     */
    public BaseException(DisplayableError error, String message, Object[] args) {
        super(message);
        this.errorCode = error;
        this.args = args;
    }

    public Object[] getArgs() {
        return args;
    }

    /**
     * Description:
     *
     * @return
     */
    public DisplayableError getError() {
        return errorCode;
    }


    public String getFullMsg() {
        if (StringUtils.isBlank(this.getMessage())) {
            return this.getError().getDisplayMsg();
        } else {
            return this.getError().getDisplayMsg() + " (" + this.getMessage() + ")";
        }
    }
}
